package top.vains.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import top.vains.entity.Files;
import top.vains.mapper.FileMapper;
import top.vains.service.IFilesService;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author vains
 * @since 2020-03-10
 */
@Service
public class FilesServiceImpl extends ServiceImpl<FileMapper, Files> implements IFilesService {

    @Override
    public List<Files> getByUserId(Integer userId, Integer type) {
        QueryWrapper<Files> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id", userId);
        if (type != -1) {
            wrapper.eq("file_type", type);
        }
        return baseMapper.selectList(wrapper);
    }

    @Override
    public List<Files> getFilesByType(Integer type, Integer userId) {
        QueryWrapper<Files> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id", userId);
        wrapper.eq("type", type);
        wrapper.orderByDesc("create_time");
        return baseMapper.selectList(wrapper);
    }
}
